﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;
//using TransferToExcel;

namespace BaMusaSoft.RPS.RPSServices.Reports
{
 
    public class AllSchedulesReport : IReport<AllSchedulesReportFields>
    {

        string excelTemplatePath;
        DataTable table;
        public AllSchedulesReport(string excelTemplatePath)
        {
            this.excelTemplatePath = excelTemplatePath;
            table = AllSchedulesReportFields.CreateDataTable();
        }

        #region "IReport"

        public void Print()
        {
            try
            {
                //ExcelMail mail = new ExcelMail();
                //mail.SendToExcel(table, excelTemplatePath, true);
            }
            catch (Exception)
            {

                throw;
            }

        }
        public void Build(IList<AllSchedulesReportFields> list)
        {
            if (list == null)
            {
                throw new ArgumentNullException("list");
            }

            try
            {
                foreach (var item in list)
                {
                    DataRow row = table.NewRow();
                    FillRow(item, row);
                    table.Rows.Add(row);
                    table.AcceptChanges();
                }

            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion

        #region "Helpers"
        private static void FillRow(AllSchedulesReportFields sourceItem, DataRow distRow)
        {
            distRow.SetField<string>("ScheduleId", sourceItem.ScheduleId);
            distRow.SetField<string>("RegistredAt", sourceItem.RegistredAt);
            distRow.SetField<int>("ContractNo", sourceItem.ContractNo);
            distRow.SetField<int>("CustomerId", sourceItem.CustomerId);
            distRow.SetField<string>("CustomerName", sourceItem.CustomerName);
            distRow.SetField<string>("PropertyNo", sourceItem.PropertyNo);
            distRow.SetField<string>("PropertyDescription", sourceItem.PropertyDescription);
            distRow.SetField<int>("AmountDue", sourceItem.AmountDue);
            distRow.SetField<string>("DateDue", Helper.PutMask(sourceItem.DateDue));
            distRow.SetField<int>("AmountPaid", sourceItem.AmountPaid);
            distRow.SetField<int>("Balance", sourceItem.Balance);
            distRow.SetField<string>("SignerName", sourceItem.SignerName);
            distRow.SetField<string>("Mobile", sourceItem.Mobile);
            distRow.SetField<string>("Phone", sourceItem.Phone);
            distRow.SetField<bool>("HadPaid", sourceItem.HadPaid);
            distRow.EndEdit();
        }
        #endregion



 
       
    }
}
